package com.zfzs.post.modules.merchant.service.impl;

import com.zfzs.post.modules.agent.service.AgentMoneyService;
import com.zfzs.post.modules.merchant.service.MerchantWebService;
import com.zfzs.post.modules.merchant.service.dto.MerchantDTO;
import com.zfzs.post.modules.merchant.service.dto.MerchantQueryCriteria;
import com.zfzs.post.modules.merchant.service.mybatis.IMerchantervice;
import com.zfzs.post.page.JpaPageHelper;
import com.zfzs.post.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;


/**
 * 商户报备实现类
 *
 * @author ck
 * @date 2018-11-23
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class MerchantWebServiceImpl implements MerchantWebService {

    @Autowired
    private IMerchantervice merchantService;

    @Autowired
    private AgentMoneyService moneyService;


    @Override
    public Map<String, Object> getMerchantInfoPage(MerchantQueryCriteria dto, Integer pageNum, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        //获取渠道ID
        Long id = SecurityUtils.getUserId();
        //管理员数据
        if (!id.equals(1L)) {
            dto.setChannelId(id);
        }
        JpaPageHelper pageHelper = merchantService.queryMerchantWebPageList(dto, pageNum, pageSize);
        map.put("content", pageHelper.getResult());
        map.put("totalElements", pageHelper.getTotalCount());
        return map;
    }

}
